package com.chidopi.market.aa.service.impl;


import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.chidopi.cdf.exception.DataAccessException;
import com.chidopi.cdf.util.ModelContextFactory;
import com.chidopi.market.aa.service.IPermissionService;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
	private IPermissionService permissionService;
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {
		try {
			this.permissionService =
				ModelContextFactory.getT("permissionService", IPermissionService.class);
			return this.permissionService.loadUserByUsername(username);
		} catch (UsernameNotFoundException eunf) {
			throw eunf;
		} catch (Exception e) {
			throw new DataAccessException(e.getMessage(), e.getCause()); //(DataAccessException) e;
		}
	}

}
